package cn.tradewin.pmp.pages.test;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.slf4j.Logger;

public class Persist1 {
	
	@Property
	@Persist(PersistenceConstants.FLASH)
	private List<String> mails;
	
	@Property
	@Persist(PersistenceConstants.FLASH)
	private String username;
	
	@Property
	@Persist(PersistenceConstants.FLASH)
	private String address;
	
	@Property
	private String mail;
	
	@Inject
	private Logger log;
	
//	@Log
//	@OnEvent(EventConstants.PREPARE)
//	void onPrepare() {
//		if (mail == null) {
//			log.debug("mail == null then step into onPrepare new ArrayList()");
//			mails = new ArrayList<String>();
//			mails.add("OnPreparexxxxxx@gmail.com");
//			mails.add("OnPrepareyyyy@hotmail.com");
//		}
//	}
//	
//	@Log
//	@OnEvent(EventConstants.ACTIVATE)
//	void onActivate() {
//		
//	}
//	
//	@Log
//	@OnEvent(EventConstants.PASSIVATE)
//	void onPassivate() {
//		
//	}
	
	
	@Log
	Object onSuccess() {
		address = "yunnan";
		if (mail == null) {
			mails = new ArrayList<String>();
			mails.add("xxxxxx@gmail.com");
			mails.add("yyyy@hotmail.com");
		}
		return Persist2.class;
	}
	
	public boolean isEmpty() {
		return (mails == null || mails.size() == 0);
	}
}